<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<script>
			//计时器   setTimeout代码会放在异步队列中，等待主线程执行完毕之后在执行
			//建议学习：JavaScript执行机制
			var a = 1;
			function test() {
				console.log(a);                      //1. undefined
				var a = 2;
				setTimeout(function() {
					console.log(a);                  //6.a = function(){a = 5;}
					a = 3;
				}, 3000);
				console.log(a);                        //2. 2
				a = 4;
				setTimeout(function() {
					console.log(a);                   //5. 不是局部a=4
					a = function(){a = 5;};
					console.log(typeof a)
				}, 0);
				console.log(a);                        //3.  4    
			}
			test();
			console.log(a);                            //4.  1
			/**
			 * 1000
			 * console.log(a);
					a = function(){a = 5;};
			 * 
			 * 3000
			 * console.log(a);
					a = 3;
			 * 
			 * 
			 * */
		</script>

	</body>

</html>